<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <meta charset="UTF-8" />
    <title>角色成员管理</title>
    <script th:src="@{/plugin/jquery/jquery-1.9.0.min.js}" type="text/javascript"></script>
    <link th:href="@{/plugin/ligerUI/skins/Aqua/css/ligerui-all.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/plugin/ligerUI/skins/Gray/css/all.css}" rel="stylesheet"/>
    <link th:href="@{/plugin/ligerUI/skins/ligerui-icons.css}" rel="stylesheet" type="text/css" />

    <script th:src="@{/plugin/ligerUI/js/core/base.js}" type="text/javascript"></script>

    <script th:src="@{/plugin/ligerUI/js/ligerui.all.js}" type="text/javascript"></script>
    <script th:src="@{/plugin/ligerUI/js/core/init-obj.js}" type="text/javascript"></script>
    <script th:inline="javascript">
        /*<![CDATA[*/
        /*]]>*/
        var tree =null;
        $(function () {
            $("#layout1").ligerLayout({leftWidth: 150});
            search();
            treDate();
        })
        function treDate() {
            tree= $("#tree8").ligerTree({
                url:'/sec/org/tree',
                ajaxType:'post',
                checkbox: true,
                parentIcon: 'folder',
                childIcon: 'leaf' ,
                slide: false, //是否显示动画
                nodeWidth: 100,
                idFieldName: 'id',
                textFieldName:'name' ,
                onError:function(node){
                    $.ligerDialog.error('组织列表加载失败!');
                }
            });
        }
        function toolbarclick(item)
        {
            var obj = dataGrid.getSelected();
            var height = $(".l-layout-center").height();
            if(item=='add') {
                var roleId = $('#id').val().toString();
                var roleName = $('#roleName').val().toString();
                parent.Back(roleId,roleName,height);
            }else if(item=='delete') {
                var roleId = $('#id').val().toString();
                var obj= dataGrid.getSelecteds();
                if(obj.length>0){
                    $.ligerDialog.confirm("确定删除所选数据吗?",function (data) {
                        if (data) {
                            var userId = '';
                            /*<![CDATA[*/
                            for (var i = 0; i < obj.length - 1; i++) {
                                userId += obj[i].id + ",";
                            }
                            userId += obj[obj.length - 1].id;
                            /*]]>*/
                            if (userId != '') {
                                $.ajax({
                                    type: 'POST',
                                    url: 'deleteTrue',
                                    data: {
                                        userId: userId,
                                        roleId:roleId
                                    },
                                    dataType: 'json',
                                    success: function (data) {
                                        dataGrid.reload();
                                    }
                                });
                            }
                        }
                    });
                }else{
                    $.ligerDialog.question("请选择要删除的数据！！！");
                }
            }else{
                treDate();
                var roleId = $('#id').val().toString();
                var digss=$.ligerDialog.open({
                    title:'添加部门',
                    target:$("#dig"),
                    height: 300,
                    width: 400,
                    buttons: [ {
                        text: '确定', onclick: function (item, dialog) {
                            var treeData=tree.getChecked()
                            var orgId = treeData[0].data.id;
                            for(var i=1;i<treeData.length;i++){
                                orgId+=','+treeData[i].data.id;
                            }
                            $.ajax({
                                type:'POST',
                                url:'addOrg',
                                data: {
                                    orgId: orgId,
                                    roleId:roleId
                                },
                                success: function (data) {
                                    $.ligerDialog.success('保存成功');
                                    tree.reload();
                                    $("input").ligerHideTip();
                                    dataGrid.reload();
                                    dialog.hide();
                                    hideOverlay();
                                },error: function (data) {
                                    $.ligerDialog.error('保存失败');
                                    tree.reload();
                                    $("input").ligerHideTip();
                                    dataGrid.reload();
                                    dialog.hide();
                                    hideOverlay();

                                }

                            })
                        } },
                        { text: '取消', onclick: function (item, dialog) {
                            tree.reload();
                            $("input").ligerHideTip(); dialog.hide();
                            hideOverlay();
                        } } ] });
            }
        }

        function callBack()
        {
            navtab.removeTabItem('add');
            navtab.removeTabItem('update');
            loadDataAptitude();
            dataGrid.reload();
        }
        function search() {
            var data = $("#searchFrom").serializeArray();
            loadDataAptitude(data);
        }
        function reset() {
            $("#searchFrom")[0].reset();
        }
        var dataGrid =null;
        //加载角色列表
        function loadDataAptitude(data){
            dataGrid   =$("#maingrid").ligerGrid({
                height: '94%',
                columns: [
                    { display: '成员账号', name: 'account',minWidth: 180 },
                    { display: '成员名称', name: 'userName',minWidth: 180 },
                    { display: '成员电话', name: 'mobile', minWidth: 400 },
                ],
                /*toolbar: {
                    items: [
                        { text: '添加成员', click: itemclick, icon: 'add',id:'add' },
                        { line: true },
                        { text: '添加部门', click: itemclick, icon: 'add',id:'addOrg' },
                        { line: true },
                        { text: '删除成员',id:'delete', click: itemclick, img: '/plugin/ligerUI/skins/icons/delete.gif' },
                        { line: true }
                    ]
                },*/
                parms:data,
                checkbox:true,
                autoFilter: true,
                dataAction:"local",
                url:"memberList",
                usePager:true,
                pageSize:"10",//分页页面大小
                pageSizeOptions:[10,20,30]//可指定每页页面大小
            });
            var s=  $(".l-panel-topbarinner .l-toolbar-item:last").find(".l-icon-search2");
            if(s.length==1){
                $(".l-panel-topbarinner .l-toolbar-item:last").remove();
            }
        }
        var tabs =null
    </script>
</head>
<body style="padding:4px">
<div id="layout1">
    <div  position="center" title="">
        <form id="searchFrom">
            <div>
                <label>角色名称</label>
                <input  name="roleName" type="text"/>
                <input  id="id" name="id" type="hidden" th:value="${id}"/>
                <input  id="roleName" name="roleName" type="hidden" th:value="${roleName}"/>
                <input name="type" type="button" onclick="search()" value="搜索"/>
                <input name="type" type="button" onclick="reset()" value="重置"/>
            </div>
        </form>
        <div style="font-size:x-large">
            <span>当前操作角色：</span><span style="color: red" th:text="${roleName}"></span>
            <!--当前操作角色：<input type="text" th:value="${roleName}">-->
        </div>
        <div>
            <a href="javascript:toolbarclick('add')">添加成员</a>
            <a href="javascript:toolbarclick('addOrg')">添加部门</a>
            <a href="javascript:toolbarclick('delete')">删除成员</a>
        </div>
        <div class="l-clear"></div>
        <div  id="maingrid">
        </div>
    </div>
</div>
<div id="dig" style="display: none">
    <ul id="tree8">
    </ul>
</div>
</body>
</html>